# -*- coding: utf-8 -*-

from core.serializers import CustomModelSerializer
from rest_framework import serializers, status
from apps.sys.models import Menu


class MenuSerializer(CustomModelSerializer):
    """
    菜单表的简单序列化器
    """

    class Meta:
        model = Menu
        fields = "__all__"
        read_only_fields = ["id"]


class MenuCreateSerializer(CustomModelSerializer):
    """
    菜单表的创建序列化器
    """
    name = serializers.CharField(required=False)

    class Meta:
        model = Menu
        fields = "__all__"
        read_only_fields = ["id"]


class MenuTreeSelectSerializer(CustomModelSerializer):
    """
    树型菜单表的序列化器
    """
    label = serializers.CharField(source='name')
    # children = serializers.SerializerMethodField(read_only=True)

    # def get_children(self, instance):
    #     query_set = Menu.objects.filter(parent=instance.id)
    #     return MenuTreeSelectSerializer(query_set, many=True, request=self.request).data

    class Meta:
        model = Menu
        fields = "__all__"
        read_only_fields = ["id"]
